package com.internetCafes.spms.web.customer.controller;

import com.internetCafes.spms.common.base.BaseWebController;
import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.common.utils.entity.page.PageItemDTO;
import com.internetCafes.spms.common.utils.entity.page.PageItemVO;
import com.internetCafes.spms.core.annotation.SysLog;
import com.internetCafes.spms.web.customer.bizservice.area.IEntAreaBizService;
import com.internetCafes.spms.web.customer.bizservice.user.IEntUserInfoBizService;
import com.internetCafes.spms.web.customer.model.user.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 企业用户数据 前端控制器
 * </p>
 *
 * @author Zj
 * @since 2021-10-15
 */
@RestController
@RequestMapping("/ent/user")
public class EntUserInfoController extends BaseWebController {

    @Autowired
    private IEntUserInfoBizService entUserInfoBizService;
    @Autowired
    private IEntAreaBizService entAreaBizService;

    /**
     * 企业用户信息删除校验
     */
    @DeleteMapping("/delete/verify/{idList}")
    @RequiresPermissions("ent:user:delete")
    public RR<EntUserDeleteVerifyRes> userInfoDeleteReturnInfo(@PathVariable List<Long> idList) {
        return RR.success(entUserInfoBizService.verifyUserDeleteByIdList(idList));
    }

    /**
     * 用户详情列表
     */
    @PostMapping("/list")
    public RR<List<EntUserListRes>> userList(@RequestBody EntUserListReq req) {
        return RR.success(entUserInfoBizService.userList(req));
    }

    /**
     * 区域名单管理 分页-销售角度
     */
    @PostMapping("/area/paging")
    @RequiresPermissions("ent:area:paging")
    public RR<PageItemVO<EntUserAreaPagingRes>> areaPaging(@RequestBody PageItemDTO<EntUserAreaPagingReq> req) {
        return RR.success(entAreaBizService.userAreaPaging(req));
    }

    /**
     * 企业用户重置密码
     */
    @SysLog("重置企业用户密码")
    @PutMapping("/reset/password/{id}")
    @RequiresPermissions("ent:user:resetPassword")
    public RR<Void> resetPassword(@PathVariable Long id) {
        return entUserInfoBizService.resetUserPassword(id) ? RR.success() : RR.fail();
    }

    /**
     * 企业用户信息删除
     */
    @SysLog("删除企业用户")
    @DeleteMapping("/{idList}")
    @RequiresPermissions("ent:user:delete")
    public RR<Void> userInfoDelete(@PathVariable List<Long> idList) {
        return entUserInfoBizService.userDelete(idList) ? RR.success() : RR.fail("此账号下有关联数据，无法删除");
    }

    /**
     * 企业用户信息修改
     */
    @SysLog("企业用户信息修改")
    @PutMapping()
    @RequiresPermissions("ent:user:update")
    public RR<Void> userInfoUpdate(@RequestBody EntUserUpdateReq req) {
        return entUserInfoBizService.userInfoUpdate(req) ? RR.success() : RR.fail();
    }

    /**
     * 分页
     */
    @PostMapping("/paging")
    @RequiresPermissions("ent:user:paging")
    public RR<PageItemVO<EntUserPagingRes>> userInfoPaging(@RequestBody PageItemDTO<EntUserPagingReq> req) {
        return RR.success(entUserInfoBizService.userInfoPaging(req));
    }
}
